using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WCSFContrib.ECommerceCatalog.BusinessEntities;
using WCSFContrib.ECommerceCatalog.CatalogData;
using WCSFContrib.ECommerceCatalog.Product.Services;

namespace WCSFContrib.ECommerceCatalog.Product.Tests.Services
{
    /// <summary>
    /// Summary description for CategoriesService.
    /// </summary>
    [TestClass]
    public class CategoriesServiceFixture
    {
        private CatalogDataSet ds;
        private CategoriesService categoriesService;

        [TestInitialize()]
        public void MyTestInitialize()
        {
            ds = new CatalogDataSet();
            ds.Category.AddCategoryRow("C1", "General1", 0);
            ds.Category.AddCategoryRow("C2", "General2", 0);
            ds.Category.AddCategoryRow("C1-A", "1-SubGeneral1", 1);
            ds.Category.AddCategoryRow("C1-B", "1-SubGeneral2", 1);
            ds.Category.AddCategoryRow("C2-A", "General3", 2);
            ds.AcceptChanges();
            categoriesService = new CategoriesService(ds);
        }

        [TestMethod]
        public void ShouldGetParentCategoryById()
        {
            Category category = categoriesService.GetCategoryById(1);
            Assert.IsNotNull(category);
            Assert.IsNull(category.ParentCategory);
            Assert.AreEqual<string>("General1", category.Name);
            Assert.AreEqual<int>(1, category.CategoryId);
        }

        [TestMethod]
        public void ShouldGetCategoryById()
        {
            Category category = categoriesService.GetCategoryById(3);
            Assert.AreEqual<int>(3, category.CategoryId);
            Assert.AreEqual<int>(1, category.ParentCategory.CategoryId);
        }

        [TestMethod]
        public void ShouldGetAllCategories()
        {
            ICollection<Category> allCategories = categoriesService.AllCategories;
            Assert.IsNotNull(allCategories);
            Assert.AreEqual<int>(5, allCategories.Count);
        }

        [TestMethod]
        public void ShouldGetSubCategories()
        {
            ICollection<Category> subCategories = categoriesService.GetSubCategories(1);
            Assert.AreEqual<int>(2, subCategories.Count);

            subCategories = categoriesService.GetSubCategories(2);
            Assert.AreEqual<int>(1, subCategories.Count);
        }

        [TestMethod]
        public void ShouldGetParentCategories()
        {
            ICollection<Category> parentCategories = categoriesService.AllParentCategories;
            Assert.AreEqual<int>(2, parentCategories.Count);
        }
    }
}
